package com.qna.web;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qna.pojo.Question;

@Controller
public class BaseController {

	@RequestMapping("/base/result")
	public String HelloController(Model model, HttpServletRequest request) {

		String desktop = System.getProperty ("user.home") + "/Desktop/yo/";
		File file = new File(desktop+"/"+request.getParameter("filename"));
		Question question = new Question();
		try {

			JAXBContext jaxbContext = JAXBContext.newInstance(Question.class);
			Unmarshaller u = jaxbContext.createUnmarshaller();
			question = (Question)u.unmarshal(file);
			model.addAttribute("userForm", question);			   
		} 
		catch (JAXBException e) {
			e.printStackTrace();
		} 
		return "showquestion";
		
	}
}